******REPLICATION MATERIALS FOR TABLES D1-D2*********************


clear
cap cd "/GhanaPaper_Governance/ReplicationFiles"

********************************************************************************
*                            Difference-in-Difference                          *
********************************************************************************

use "./Data/pol_baseline_AuditsPaper.dta"
destring district_n triplet trt condition list_3 audit_score surveyexp3 survey_wave ndc_majority, replace
keep district_n triplet trt condition list_3 audit_score surveyexp3 survey_wave ndc_majority hcomp
save "./Data/pol_baseline_AuditsPaper_temp.dta", replace 

clear 
use "./Data/pol_endline_AuditsPaper.dta"
gen endline_note=1
keep district_n triplet trt condition list_3 audit_score surveyexp3 survey_wave ndc_majority endline_note hcomp
append using "./Data/pol_baseline_AuditsPaper_temp.dta", force

* Drop observations in CSO districts
drop if condition == "CSO"

* GAS treatment arm
*drop gas 
gen gas=.
replace gas = 1 if condition == "GAS"
replace gas = 0 if condition == "Control"

* timevar = 1 for endline
gen timevar=.
replace timevar = 0 
replace timevar = 1 if endline_note == 1 

* NLS Estimator 

  * -> Firs Step
poisson surveyexp3 i.timevar##i.gas if list_3==0, vce(cluster triplet)
eststo m1
predict yhat_nls1
generate y_surveyexp3 = surveyexp3 - yhat_nls1

  *-> Second Step
nl (y_surveyexp3 = {b0}+{b1}*timevar+{b2}*gas+{b3}*timevar*gas) if list_3==1, cluster(triplet) vce(bootstrap, reps(1000)) variables (timevar gas)
eststo m2
estat ic
drop yhat_nls1 y_surveyexp3
***


* NLS Estimator (Electoral Competition as control)
*gen did_timegas = timevar*gas
  * -> Firs Step
poisson surveyexp3 i.timevar##i.gas hcomp if list_3==0, vce(cluster triplet)
eststo m3
predict yhat_nls1
generate y_surveyexp3 = surveyexp3 - yhat_nls1

  *-> Second Step
nl (y_surveyexp3 = {b0}+{b1}*timevar+{b2}*gas+{b3}*timevar*gas+{b4}*hcomp) if list_3==1, cluster(triplet) vce(bootstrap, reps(1000)) variables (timevar gas hcomp)
eststo m4
estat ic
drop yhat_nls1 y_surveyexp3
***

esttab m1 m3 using Stage1_table.tex, label se pr2 aic n title(First Stage) addnote("Note: Standard errors clustered at the Triplet level.") replace

esttab m2 m4 using Stage2_table.tex, label se pr2 aic n title(Second Stage) addnote("Note: Bootstrap standard errors clustered at the Triplet level.") replace

eststo clear

* NLS Estimator ((neg) Audit Score as control)
*gen did_timegas = timevar*gas
  * -> Firs Step
poisson surveyexp3 i.timevar##i.gas audit_score if list_3==0, vce(cluster triplet)

predict yhat_nls1
generate y_surveyexp3 = surveyexp3 - yhat_nls1

  *-> Second Step
nl (y_surveyexp3 = {b0}+{b1}*timevar+{b2}*gas+{b3}*timevar*gas+{b4}*audit_score) if list_3==1, cluster(triplet) vce(bootstrap, reps(1000)) variables (timevar gas audit_score)
estat ic
drop yhat_nls1 y_surveyexp3
***

